<?php
/*
	Copyright 2006, 2007, 2008, 2009, 2010 Bastiaan Grutters
    
    This file is part of Ages of Strife website.

    Ages of Strife website is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Ages of Strife website is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Ages of Strife website.  If not, see <http://www.gnu.org/licenses/>.
 */
include( '../global/initialize.php' );

aos_header( 'Translate' );

$page = 1;
if( isset( $_GET[ 'page' ] ) && is_numeric( $_GET[ 'page' ] ) ) {
	$page = $_GET[ 'page' ];
}

$filter = '';
if( isset( $_GET[ 'filter' ] ) ) {
	$filter = $_GET[ 'filter' ];
}
$per_page = 6;
global $language;

$language_info = translations_get_language_information( $language );

$query = "SELECT admin FROM users WHERE user_id = " . $_SESSION[ 'user_id' ];
$result = mysql_query( $query ) or die( "Query failed : " . mysql_error() );
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if( ( isset( $row[ 'admin' ] ) && $row[ 'admin' ] == 1 ) || $language_info[ 'user_id' ] == $_SESSION[ 'user_id' ] ) {
	$moderator = true;
}
else {
	$moderator = false;
}

$max_page = ceil( $language_info[ 'untranslated' ] / $per_page );
$end = $page * $per_page;
if( $end > $language_info[ 'untranslated' ] ) {
	$end = $language_info[ 'untranslated' ];
}
?>
					<div class="blok">
						<a href="translate.php"><?php transprint( 'To language overview' ); ?></a>
					</div>
					<br />
					<div class="blok">
						<strong><?php transprint( 'Filter' ); ?></strong><br />
						<form method="get" action="translate_text.php">
							<input type="hidden" name="page" value="<?php print( $page );  ?>" />
							<input type="text" size="20" name="filter" value="<?php print( $filter );  ?>" />
							<input type="submit" value="<?php transprint( 'Filter' );  ?>" />
						</form>
					</div>
					<br />
<?php

if( isset( $_SESSION[ 'translate_status' ] ) ) {
	print( "\t\t\t\t<div class=\"blok\">\r\n\t\t\t\t" . $_SESSION[ 'translate_status' ] . "\r\n\t\t\t\t</div><br />\r\n" );
	unset( $_SESSION[ 'translate_status' ] );
}

if( $language_info[ 'untranslated' ] > 0 ) {
	if( $filter == '' ) {
?>
					<div class="blok translation-container">
<?php
		$count = ': ' . number_format( ( $page - 1 ) * $per_page ) . ' - ' . number_format( $end ) . ' out of ' . number_format( $language_info[ 'untranslated' ] );
?>
						<strong><?php transprint( 'Untranslated' ); print( $count ); ?></strong><br />
<?php
	}
	else {
?>
						<strong><?php transprint( 'Untranslated' ); ?>: <?php print( htmlentities( $filter ) ); ?></strong><br />
<?php
	}
	
	$texts = translations_get_untranslated( $language, $page, $per_page, $filter );
	foreach( $texts AS $text ) {
		translations_print_translate_form( $text, 'submit_translation.php?page=' . $page, $moderator );
?>
						<br />
						<br />
<?php		
	}

	if( $page > 1 ) {
?>
						<div id="text_left">
							<a href="translate_text.php?page=<?php print( $page - 1 ); ?>&filter=<?php print( $filter ); ?>"><?php transprint( 'Previous' ) ?></a>
						</div>
<?php		
	}
	
	if( $page < $max_page ) {
?>
						<div id="text_right">
							<a href="translate_text.php?page=<?php print( $page + 1 ); ?>&filter=<?php print( $filter ); ?>"><?php transprint( 'Next' ) ?></a>
						</div>
<?php		
	}
	
	if( $page < $max_page || $page > 1 ) {
		print( "<br />" );
	}
?>						
					</div>
<?php
}
else {
?>
					<div class="blok">
						<strong><?php transprint( 'All text is translated' ); ?></strong><br />
						<?php transprint( 'It could be some text is still awaiting approval and some parts of the site are not yet made ready to be translated.' ); ?><br />
						<?php transprint( 'But all that can currently be translated is translated.' ); ?><br />
					</div>
<?php
}
aos_footer();
?>